class JobItem {
    Staff staff
    Product product
    BigDecimal quantity = 0
    BigDecimal price = 0
    Job job
    String status = Constants.JOB_STATUS_CREATED

    BigDecimal getValue() {
        return (quantity * price).setScale(2)
    }

    BigDecimal getCommission() {
        if (job.status == Constants.JOB_STATUS_CREATED || job.status == Constants.JOB_STATUS_PENDING)
            return 0
        CommissionPolicy commissionPolicy = staff?.commissionPolicyGroup?.searchCommissionPolicyByProduct(product)
        if (commissionPolicy) {
            if (commissionPolicy instanceof QuantityCommissionPolicy)
                return ((QuantityCommissionPolicy) commissionPolicy).calculateCommission(this)
            else if (commissionPolicy instanceof PercentageCommissionPolicy)
                return ((PercentageCommissionPolicy) commissionPolicy).calculateCommission(this)
        } else
            return 0
    }

    static transients = ['value', 'commission']
    static belongsTo = Job

    String toString() {
        return "$product 数量：$quantity 价格：$price [金额：${value.setScale(2, BigDecimal.ROUND_HALF_UP)}] 经手人员:$staff"
    }

}
